package com.heima.admin.job;

import com.heima.admin.service.WmNewsAutoScanService;
import com.heima.feigns.wemedia.WemediaFeign;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class WeMediaNewsAutoScanJob {

    @Autowired
        WemediaFeign wemediaFeign;

    @Autowired
    WmNewsAutoScanService wmNewsAutoScanService;

    @XxlJob("wemediaAutoScanJob") //注解+任务名
    public ReturnT wmAutoScanJob(String param){
        log.info("=================>开始定时发布待发布文章");
        //1.查询待发布文章(调用方法)
        List<Integer> releaseList = wemediaFeign.findRelease();
            //判断:如果获取到的集合不为空,则调用自动发布
        if(releaseList!=null && releaseList.size()>0) {
            //2.自动发布文章
            releaseList.forEach(wmNewsAutoScanService::autoScanByMediaNewsId); //遍历待发布id,逐个发布
        }
        return ReturnT.SUCCESS;
    }
}
